<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%--<x:parse xml="${param.xmlstr}" var="xmlData" />--%>
<%--<div class="t_bar">--%>
<%--&lt;%&ndash;<span class="color_red">*</span>&ndash;%&gt;--%>
<%--项目基本情况--%>
<%--</div>--%>
<c:set var="nature_value">
    <x:out select="$xmlData/data/organizations/organization[@submit_org='1']/nature_value" />
</c:set>

<div class="t_bar">
    <strong>项目课题信息 (最多添加5行)</strong>
</div>

<table id="subject" border="0" cellspacing="0" cellpadding="0" style="width: 100%" class="table01 t_css">
    <thead>
    <tr >
        <th align="center" width="4%">选择</th>
        <th align="center" width="4%">序号</th>
        <th align="center" width="9%">课题名称</th>
        <th align="center" width="9%">课题主持人</th>
        <th align="center" width="12%">出生年月</th>
        <th align="center" width="14%">职称</th>
        <th align="center" width="10%">职务</th>
        <th align="center" width="8%">单位</th>
        <th align="center" width="10%">联系电话</th>
        <th align="center" width="7%">课题经费（万元）</th>
        <th align="center" width="7%">自筹经费（万元）</th>
        <th align="center" width="6%">是否长三角区域</th>
    </tr>
    </thead>
    <tbody id="subject_tab">
    <tr style="display: none" align="center">
        <td align="center">
            <input type="radio" class="radiobutton" name="selAttendOrg11">
        </td>
        <td align="center">
            <span name="subjects|subject[0]@seq_no">[index]</span>
        </td>
        <td align="center">
            <input name="subjects|subject[0]|sub_name" label="课题名称" type="text" required class="input_css required  maxlength:300" style="width: 80%;" maxlength="100" value="" />
        </td>

        <td align="center">
            <input name="subjects|subject[0]|sub_psn" label="课题主持人" type="text" required class="input_css  maxlength:300" style="width: 80%;" maxlength="100" value="" />
        </td>

        <td align="center">
            <cpt:date id="birth_date[index]"
                      name="subjects|subject[0]|basic_info|birth_date" size="8"
                      value="" className=" date" label="出生年月"></cpt:date>
        </td>

        <td align="center">
            <cpt:tree key="prof_title" cacheable="false" className="input_css " readonly="true" value="" label="职称"
                      width="60%"
                      id="title[index]" name="title[0][0]" showPattern="current" shieldPattern="0" topCheckbox="false"
                      onClick="initTreeValue2"/>
            <input type="hidden" name="subjects|subject[0][0]|title_value" id="title[index]_value" class=""
                   value="" label="职称"/>
            <input type="hidden" name="subjects|subject[0][0]|title_name" id="title[index]_name" value=""/>
        </td>
        <td align="center">
            <input name="subjects|subject[0]|sub_post" label="职务" type="text" required class="input_css  maxlength:300" style="width: 80%;" maxlength="100" value="" />
        </td>
        <td align="center">
            <input name="subjects|subject[0]|sub_unit" label="单位" type="text" required class="input_css  maxlength:300" style="width: 80%;" maxlength="100" value="" />
        </td>
        <td align="center">
            <input name="subjects|subject[0]|psn_phone" label="联系电话" type="text" required class="input_css  " maxlength="18" style="width: 80%;" value="" />
        </td>
        <td align="center">
            <input name="subjects|subject[0]|sub_fund" label="课题经费" type="text" class="input_css " style="width: 80%;text-align: right;" maxlength="100" value="" onfocus="InitInput.setNumber(this,9,2,2)"  />
        </td>
        <td align="center">
            <input name="subjects|subject[0]|self_fund" label="自筹经费" type="text" class="input_css " style="width: 80%;text-align: right;" maxlength="100" value="" onfocus="InitInput.setNumber(this,9,2,2)"  />
        </td>
        <td align="center">
            <cpt:select id="triangle_reg[index]" key="no_yes" name="triangle_reg" onChange="initControlValue(this.id);" value="" style="width:85%"></cpt:select>
            <input type="hidden" name="subjects|subject[0]|triangle_reg_value" class="" value=""  label="是否长三角区域" />
            <input type="hidden" name="subjects|subject[0]|triangle_reg_name" value=""/>
        </td>


    </tr>
    <c:set value="0" var="index" scope="page" />
    <x:forEach select="$xmlData/data/subjects/subject" var="subject">

        <c:choose>
            <c:when test="${index<10}">
                <c:set value="0" var="flag" scope="page" />
            </c:when>
            <c:otherwise>
                <c:set value="" var="flag" scope="page" />
            </c:otherwise>
        </c:choose>
        <tr align="center">
            <td>
                <input type="radio" class="radiobutton" name="selAttendOrg11">
            </td>
            <td align="center">
					<span name="subjects/subject[${flag}${index}]@seq_no">
						<x:out select="$subject/@seq_no" />
					</span>
            </td>
            <td>
                <input name="subjects/subject[${flag}${index}]/sub_name" label="课题名称" type="text" required class="input_css required maxlength:100" style="width: 80%;" maxlength="100"
                       value="<x:out select="$subject/sub_name" />" />
            </td>

            <td align="center">
                <input name="subjects/subject[${flag}${index}]/sub_psn" label="课题主持人" type="text" required class="input_css  maxlength:300" style="width: 80%;" maxlength="100"
                       value="<x:out select="$subject/sub_psn" />" />
            </td>
            <td align="center">
                <c:set var="birth_date">
                    <x:out select="$subject/basic_info/birth_date" />
                </c:set>
                <cpt:date id="birth_date${index}"
                          name="subjects/subject[${flag}${index}]/basic_info/birth_date"
                          size="8" value="${birth_date}" className=" date"
                          label="出生年月"></cpt:date>
            </td>
            <td align="center">
                <c:set var="title">{'id':'<x:out select="$subject/title_value"/>','name':'<x:out
                        select="$subject/title_name"/>'}</c:set>
                <cpt:tree key="prof_title" cacheable="false" className="input_css" readonly="true" value="${title}"
                          label="职称" width="60%"
                          id="title${flag}${index}" name="title${flag}${index}" showPattern="current" shieldPattern="0"
                          topCheckbox="false" onClick="initTreeValue2"/>
                <input type="hidden" id="title${flag}${index}_value"
                       name="subjects/subject[${flag}${index}]/title_value" class=""
                       value="<x:out select="$subject/title_value" />" label="职称"/>
                <input type="hidden" id="title${flag}${index}_name"
                       name="subjects/subject[${flag}${index}]/title_name"
                       value="<x:out select="$subject/title_name" />"/>
            </td>
            <td align="center">
                <input name="subjects/subject[${flag}${index}]/sub_post" label="职务" type="text" required class="input_css  maxlength:300" style="width: 80%;" maxlength="100"
                       value="<x:out select="$subject/sub_post" />" />
            </td>
            <td align="center">
                <input name="subjects/subject[${flag}${index}]/sub_unit" label="单位" type="text" required class="input_css  maxlength:300" style="width: 80%;" maxlength="100"
                       value="<x:out select="$subject/sub_unit" />" />
            </td>
            <td align="center">
                <input name="subjects/subject[${flag}${index}]/psn_phone" label="联系电话" type="text" required class="input_css  maxlength:300" style="width: 80%;" maxlength="100"
                       value="<x:out select="$subject/psn_phone" />" />
            </td>
            <td align="center">
                <input name="subjects/subject[${flag}${index}]/sub_fund" label="课题经费" type="text" required class="input_css " style="width: 80%;text-align: right;" maxlength="100" onfocus="InitInput.setNumber(this,7,2,2)"
                       value="<x:out select="$subject/sub_fund" />" />
            </td>
            <td align="center">
                <input name="subjects/subject[${flag}${index}]/self_fund" label="自筹经费" type="text" required class="input_css " style="width: 80%;text-align: right;" maxlength="100" onfocus="InitInput.setNumber(this,7,2,2)"
                       value="<x:out select="$subject/self_fund" />" />
            </td>
            <td>
                <c:set var="triangle_reg"><x:out select="$subject/triangle_reg_value" /></c:set>
                <cpt:select id="triangle_reg${flag}${index}" key="no_yes" name="triangle_reg" onChange="initControlValue(this.id);" value="${triangle_reg }" style="width:85%"></cpt:select>
                <input type="hidden" name="subjects/subject[${flag}${index}]/triangle_reg_value" class="" value="<x:out select="$subject/triangle_reg_value" />"  label="是否长三角区域" />
                <input type="hidden" name="subjects/subject[${flag}${index}]/triangle_reg_name" value="<x:out select="$subject/triangle_reg_name" />"/>
            </td>

        </tr>
        <c:set var="beggerClass"></c:set>
        <c:set value="${index+1}" var="index" scope="page" />
    </x:forEach>
    </tbody>
</table>

<table width="98%" class="not_table">
    <tr>
        <td>
            <input class="button_02" type="button" name="cmdAddbefore" value="添加" onclick="if(checkTabLimit('subject',5,'项目课题信息最多只能填写5条')){addNewRow('subject');change_cs();getLen();}try{top.resizeFrame();}catch(e){};" />
            <input class="button_02" name="cmdMovePrev" type="button" value="上移" onclick="movePrev('subject');change_cs()" />
            <input class="button_02" name="cmdMoveNext" type="button" value="下移" onclick="moveNext('subject');change_cs()" />
            <input class="button_02" name="cmddel" type="button" value="删除" onclick="deleteSelectedRow('subject','项目课题信息');change_cs();getLen();" />
        </td>
    </tr>
</table>
<input type="hidden" id="if_have_org" name="proposal/if_have_org">


<script type="text/javascript">
    $(function(){
        emerging_enterprises();
        $("#tab1").click();
        $("#fragment-tab1 :text,#fragment-tab1 [type='date']").addClass("input_width");
        $("#fragment-tab1 select").addClass("select_width");
        $("table.t_css").each(function(){
            $(this).find("tr").not(".cbTable tr").filter(":even").addClass("li_1");
            $(this).find("tr").not(".cbTable tr").filter(":odd").addClass("li_2");
        });
    });

    $(document).ready (function() {
        compare_age();
        getLen();
        // emerging_enterprises();
    });
    /*function initTreeValueExt(treeId, treeNode) {
        if ((treeNode && treeNode.isParent)) {
            scmWarn("请选择具体的" + $("#" + treeId).attr("label"));
            $("#" + treeId).val("");
            $("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId + "_code']").val("");
            $("#" + treeId).parents("td").find("[name$='" + treeId + "_value'],[id$='" + treeId + "_value']").val("");
            $("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId + "_name']").val("");
            return false;
        }
        var str = treeNode.name;
        var obj = treeNode.parentNode;
        while (obj != null) {
            str = obj.name + "-" + str;
            obj = obj.parentNode;
        }

        $("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId + "_code']").val(treeNode.id);
        $("#" + treeId).parents("td").find("[name$='" + treeId + "_value'],[id$='" + treeId + "_value']").val(treeNode.id);
        $("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId + "_name']").val(str);
    }*/

    function initTreeValueExt(treeId, treeNode) {
        if (!(treeNode && (treeNode.level > 0 || !treeNode.isParent))) {
            scmWarn($("#" + treeId).attr("label") + messageTip.researchAreaInvalidDisciplineCode);
            if (treeNode.level == 0) {
                $("#" + treeId).val("");
                $("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId+ "_code']").val("");
                $("#" + treeId).parents("td").find("[name$='" + treeId + "_value'],[id$='" + treeId+ "_value']").val("");
                $("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId+ "_name']").val("");
            }

            return false;
        }


        var str = treeNode.name;
        var obj = treeNode.parentNode;
        while (obj != null) {
            obj = obj.parentNode;
        }

        $("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId+ "_code']").val(treeNode.id);
        $("#" + treeId).parents("td").find("[name$='" + treeId + "_value'],[id$='" + treeId+ "_value']").val(treeNode.id);
        $("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId+ "_name']").val(str);
    }

    /**
     *申报人年龄大于57岁，第五个附件为必传
     * @Author huangxiongwei
     * @Date 2019/8/23 15:59
     * @Version V1.0
     */
    function compare_age() {
        var end_date = ${statYear}+"-01"+"-01";
        var birthday = $("#fzbirthday").val();

        var end_date_year = Number(end_date.substring(0,4));
        var birthday_year = Number(birthday.substring(0,4));

        var end_date_month = Number(end_date.substring(5,7));
        var birthday_month = Number(birthday.substring(5,7));

        var end_date_day = Number(end_date.substring(8));
        var birthday_day = Number(birthday.substring(8));

        var different_value = end_date_year - birthday_year -57;
        var different_value1 = end_date_month - birthday_month;
        var different_value2 = end_date_day - birthday_day;

        if(different_value > 0 || (different_value == 0 && different_value1 > 0 )  || (different_value == 0 && different_value1 == 0  && different_value2 > 0)){
            $("#age").val(1);
        }else {
            $("#age").val(0);
        }
        /*onchangeType2();*/

    }

    function onchangeType2(){
        var age = $("#age").val();
        if(age =='1'){
            $("#prpContent_upload tr").each(function(){
                var attachName = $(this).find("td:eq(1) span[name$='name']").text();
                if(attachName=="申报人超过57周岁，申报单位需出具其能完成项目实施的承诺函（如返聘、延迟退休等）"){
                    $(this).find("td:eq(2) span[name$='berif']").text("是");
                }
            });
        }else{
            $("#prpContent_upload tr").each(function(){
                var attachName = $(this).find("td:eq(1) span[name$='name']").text();
                if(attachName=="申报人超过57周岁，申报单位需出具其能完成项目实施的承诺函（如返聘、延迟退休等）"){
                    $(this).find("td:eq(2) span[name$='berif']").text("否");
                }

            });
        }

    }

    $(document).ready(function(){
        if($('input:checkbox[name="enterprise_scale"]:checked').val()=="中小企业"){
            $("#technologyEnterprise").removeAttr("disabled");
        }else{
            $("#technologyEnterprise").attr("disabled",true);
        }
    });

    /***
     * 勾选中小型企业框时打开科技型中小企业选择
     * 没有勾选时关闭科技型中小企业选择，并清除隐藏域的值
     *
     */
    function removeDisabled(){
        if($('input:checkbox[name="enterprise_scale"]:checked').val()=="中小企业"){
            $("#technologyEnterprise").removeAttr("disabled");
        }else{
            $("#technologyEnterprise").removeAttr("checked");
            $("#technology_enterprise_value").val("");
            $("#technologyEnterprise").attr("disabled",true);
        }
    };


    function synchronizationAmount(){
        var request_amount=$("#request_amount").val();
        if(request_amount !=  ""){
            $("#total_each_0").val(parseFloat($("#request_amount").val()).toFixed(2));

            countFundAuto('total_','each_0,each_1,each_2,each_4','investfrom_5');
        }else if(request_amount ==  ""){
            $("#total_each_0").val("");
            countFundAuto('total_','each_0,each_1,each_2,each_4','investfrom_5');
        }

    }

    $(function() {
        $("#subject tr:even").addClass("li_1");
        $("#subject tr:odd").addClass("li_2");
    });


    function change_cs(){
        $("#subject tr:even").removeClass().addClass("li_1");
        $("#subject tr:odd").removeClass().addClass("li_2");
    }

    function initSubjectTreeValueExp(treeId, treeNode) {
        /* if (!(treeNode && (treeNode.level > 0 || !treeNode.isParent))) {
            // scmWarn($("#" + treeId).attr("label") + "不能选择第一级，请选择它的子级！");
             if (treeNode.level == null) {
                 $("#" + treeId).val("");
                 $("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId + "_code']").val("");
                 $("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId + "_name']").val("");
             }
             return false;
         }*/
        $("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId + "_code']").val(treeNode.id);
        $("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId + "_name']").val(treeNode.name.substring(treeNode.name.indexOf(".") + 1));
        //触发研究方向
        //checkDisCodeExp(treeNode.id,treeId,true); //下拉树
        //checkDisCodeSelect(treeNode.id,treeId,true);
    }

    /*function fund_compare() {
        var total_each =  (Number($("#total_each_0").val())*100 + Number($("#total_each_1").val())*100 + Number($("#total_each_2").val())*100+ Number($("#total_each_3").val())+ Number($("#total_each_4").val())*100)/100;
        $("#total_investfrom_5").val(total_each);
    }*/
    function synchronizationAmount1(){
        var built_institute=$("#built_institute").val();
        if(built_institute !=  ""){
            $("span[id='built_institute_[00]']").html($("#built_institute").val());
            /*$("#total_fund_18").val(parseFloat($("#request_amount").val()).toFixed(2));*/
        }else if(built_institute ==  ""){
            $("span[id='built_institute_[00]']").html("");
        }
    }

    function getLen() {
        var len=$("#subject tr:gt(1)").length;
        if(len>0){
            $("#if_have_org").val("1");
        }else{
            $("#if_have_org").val("0");
        }
    }

    function emerging_industries() {
        var emerging_industries_value = $("#emerging_industries_value").val();
        if(emerging_industries_value==0){
            $("#emerging_industries").val(1);
        }else if(emerging_industries_value==1){
            $("#emerging_industries").val(0);
        }else {
            $("#emerging_industries").val("");
        }
    }


    function emerging_enterprises() {
        var emerging_enterprises_value = $("#emerging_enterprises_value").val();
        if (emerging_enterprises_value == "0") {
            $("#emerging_industries_value_div").attr("style","display:block");
            $("#emerging_industries_value").addClass("required");
        } else{
            $("#emerging_industries_value_div").attr("style","display:none");
            $("input[name='proposal/emerging_industries_value']").val('');
            $("input[name='proposal/emerging_industries_name']").val('');
            $("#checkbox_dyn_emerging_industries").find("td input[type='checkbox']").attr("checked",false);
            $("#emerging_industries_value").removeClass("required");
        }
    }

</script>
